package top.ryw.ssm2.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.ryw.ssm2.pojo.Dept;
import top.ryw.ssm2.pojo.User;
import top.ryw.ssm2.service.DeptService;
import top.ryw.ssm2.service.UserService;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/dept")
public class DeptController {

    @Resource
    private DeptService deptService;

    @RequestMapping("/list")
    @ResponseBody
    public Object list() {
        PageHelper.startPage(1, 10);
        List<Dept> depts = deptService.selectList();
        PageInfo<Dept> deptPageInfo = new PageInfo<Dept>(depts);
        return deptPageInfo;


    }

    @RequestMapping("/add")
    @ResponseBody
    public Object add() {
        for (int i = 0; i < 10; i++) {
            Dept dept = new Dept();

            dept.setDeptName("deptName" + i);
            deptService.insert(dept);

        }
        return "添加成功";


    }
}
